<template>
	<view class="content">
		<view class="deviceBox">
			<view class="text">设备ID</view>
			<view class="inputBox">
				<input type="text" placeholder="请输入设备ID" v-model="deviceIdValue" />
			</view>
		</view>
		<view class="deviceBox">
			<view class="text">设备名称</view>
			<view class="inputBox">
				<input type="text" placeholder="请输入设备名称" v-model="deviceNameValue" />
			</view>
		</view>
		<view class="finishBox">
			<view class="finishBtn" @click="createDevice" >完成</view>
		</view>
	</view>
</template>

<script setup>
	import { ref } from 'vue';
	import {
		onLoad,
		onUnload
	} from '@dcloudio/uni-app'
	const deviceIdValue = ref(''); // 设备ID
	const deviceNameValue = ref(''); // 设备名称 addBindDev
	
	onLoad((options) => {
	  let code=decodeURIComponent(options.uid);
	  if (code) {
	    deviceIdValue.value = code;
	  }
	});
	
	const createDevice=()=>{
		let data={
			equipNo:deviceIdValue.value,
			devName:deviceNameValue.value
		}
		uni.$u.http.post('/wechat/addBindDev',data).then(res => {
		  if(res.success){
			  uni.showToast({
			  	title: '添加成功',
			  	icon: 'success'
			  })
			  setTimeout(() => {
			  	uni.switchTab({
			  		url: '/pages/index/index'
			  	})
			  }, 1500)
		  }
		}).catch(e => {
		  console.log(e, '添加失败');
		})
		
	}
	
	
</script>

<style lang="scss" scoped>
	.deviceBox{
		width: 70%;
		margin: 0 auto;
		margin-top: 50rpx;
		.text{
			font-size: 32rpx;
		}
		.inputBox{
			width: 100%;
			height: 120rpx;
			background-color: #F5F5F5;
			margin-top: 40rpx;
			border-radius: 30rpx;
			input{
				width: 92%;
				height: 120rpx;
				margin-left: 4%;
			}
		}
	}
	.finishBox{
		width: 100%;
		height: 150rpx;
		background-color: #fff;
		position: fixed;
		bottom: 50rpx;
		left: 0;
		display: flex;
		align-items: center;
		justify-content: center;
		.finishBtn{
			width: 94%;
			height: 120rpx;
			background:#3251C0;
			border-radius: 10rpx;
			display: flex;
			align-items: center;
			justify-content: center;
			color: #fff;
		}
	}
</style>
